package com.tancire.arts.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.arts.domain.NoteComposition;
import com.tancire.arts.service.INoteCompositionService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 作品集Controller
 *
 * @author chenchao
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/arts/composition")
public class NoteCompositionController extends BaseController {
    @Resource
    private INoteCompositionService noteCompositionService;

    /**
     * 查询作品集列表
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:list')")
    @GetMapping("/list")
    public TableDataInfo list(NoteComposition noteComposition) {
        startPage();
        List<NoteComposition> list = noteCompositionService.selectNoteCompositionList(noteComposition);
        return getDataTable(list);
    }

    /**
     * 导出作品集列表
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:export')")
    @Log(title = "作品集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NoteComposition noteComposition) {
        List<NoteComposition> list = noteCompositionService.selectNoteCompositionList(noteComposition);
        ExcelUtil<NoteComposition> util = new ExcelUtil<NoteComposition>(NoteComposition.class);
        util.exportExcel(response, list, "作品集数据");
    }

    /**
     * 获取作品集详细信息
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(noteCompositionService.selectNoteCompositionById(id));
    }

    /**
     * 新增作品集
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:add')")
    @Log(title = "作品集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NoteComposition noteComposition) {
        return toAjax(noteCompositionService.insertNoteComposition(noteComposition));
    }

    /**
     * 修改作品集
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:edit')")
    @Log(title = "作品集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NoteComposition noteComposition) {
        return toAjax(noteCompositionService.updateNoteComposition(noteComposition));
    }

    /**
     * 删除作品集
     */
    @PreAuthorize("@ss.hasPermi('arts:composition:remove')")
    @Log(title = "作品集", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(noteCompositionService.deleteNoteCompositionByIds(ids));
    }
}
